package Exceptions;

import java.util.Scanner;

/**
 * @author yangwenqi
 * @decs TODO
 * @date 2025/4/27
 */
public class ExceptionTest {
    private int a;
    private int b;
    private int c;

    public ExceptionTest() {
    }

    public ExceptionTest(int a, int b, int c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }
    /**
     * 获取
     * @return a
     */
    public int getA() {
        return a;
    }

    /**
     * 设置
     * @param a
     */
    public void setA(int a) {
        this.a = a;
    }

    /**
     * 获取
     * @return b
     */
    public int getB() {
        return b;
    }

    /**
     * 设置
     * @param b
     */
    public void setB(int b) {
        this.b = b;
    }

    /**
     * 获取
     * @return c
     */
    public int getC() {
        return c;
    }

    /**
     * 设置
     * @param c
     */
    public void setC(int c) {
        this.c = c;
    }

    public String toString() {
        return "ExceptionTest{a = " + a + ", b = " + b + ", c = " + c + "}";
    }
    public static void main(String[] args) {
        ExceptionTest ex = new ExceptionTest();
        Scanner sc = new Scanner(System.in);
        while (true) {
            try {
                System.out.println("请输入一个整数：");
                String s1 = sc.nextLine();
                ex.setA(Integer.parseInt(s1));
                System.out.println("请输入一个整数：");
                String s2 = sc.nextLine();
                ex.setB(Integer.parseInt(s2));
                int c = ex.getA()/ex.getB();
                ex.setC(c);
                System.out.println(ex.getA()+"/"+ex.getB()+"=" + ex.getC());
                break;
            } catch (NumberFormatException e) {
                System.out.println("输入的数字格式有误！");
            }catch (ArithmeticException e){
                System.out.println("除数不能为0");
            }
        }
    }
}
